package com.bishe.app.modules.menu.valid;

import com.bishe.app.core.common.BizException;
import com.bishe.app.modules.menu.entity.Menu;
import com.bishe.app.modules.menu.enums.MenuType;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * Created : 2024/3/15, 17:07
 *
 * @author : jeffrey.hu
 **/
@Component
public class MenuValidator {

    public void validCreate(Menu menu) {
        if (menu == null) {
            throw new BizException("请求参数不能为空");
        }

        if (menu.getParentId() == null || menu.getParentId() == 0) {
            if (Objects.equals(menu.getType(), MenuType.BTN.getCode())) {
                throw new BizException("按钮不能作为一级菜单。");
            }
        }
    }
}
